package com.ktgj.flight.service.impl;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.TimeUnit;

import com.alibaba.druid.sql.visitor.functions.If;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ktgj.common.core.annotation.Excel;
import com.ktgj.common.core.constant.BusinessTypeConstants;
import com.ktgj.common.core.constant.FlightOrderConstants;
import com.ktgj.common.core.domain.R;
import com.ktgj.common.core.enums.EmHelper;
import com.ktgj.common.core.utils.SnowflakeUtils;
import com.ktgj.common.redis.service.RedisService;
import com.ktgj.customer.api.RemoteCustomerService;
import com.ktgj.customer.api.domain.*;
import com.ktgj.flight.common.linkstar.LinkStar;
import com.ktgj.flight.domain.*;
import com.ktgj.flight.domain.InterfaceEntity.MoPassenger;
import com.ktgj.flight.domain.InterfaceEntity.MoQueryOrderRequest;
import com.ktgj.flight.domain.InterfaceEntity.MoQueryOrderResponse;
import com.ktgj.flight.domain.InterfaceEntity.MoSegment;
import com.ktgj.flight.domain.vo.*;
import com.ktgj.flight.mapper.*;
import com.ktgj.flight.util.IDCardUtil;
import com.ktgj.pay.api.RemotePayService;
import com.ktgj.pay.api.domain.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.flight.service.IIflightOrderService;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;

/**
 * 国际机票订单Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-05-31
 */
@Service
public class IflightOrderServiceImpl implements IIflightOrderService 
{
    private static String FLIGHT = "flight:";

    private static String ORDER = "order:";

    @Autowired
    private IflightOrderMapper iflightOrderMapper;
    @Autowired
    private LinkStar linkStar;
    @Autowired
    private AirlinerMapper airlinerMapper;
    @Autowired
    private AirportMapper airportMapper;
    @Autowired
    private RemoteCustomerService remoteCustomerService;
    @Autowired
    private IflightPassengerMapper iflightPassengerMapper;
    @Autowired
    private IflightPaymentMapper iflightPaymentMapper;
    @Autowired
    private IflightOrderInvoiceMapper iflightOrderInvoiceMapper;
    @Autowired
    private RemotePayService remotePayService;
    @Autowired
    private RedisService redisService;
    @Autowired
    private IflightRefundMapper iflightRefundMapper;
    @Autowired
    private IflightRefundbankcardMapper iflightRefundbankcardMapper;
    @Autowired
    private IflightRefundandpassengerMapper iflightRefundandpassengerMapper;

    /**
     * 查询国际机票订单
     * 
     * @param id 国际机票订单ID
     * @return 国际机票订单
     */
    @Override
    public IflightOrder selectIflightOrderById(Long id)
    {
        return iflightOrderMapper.selectIflightOrderById(id);
    }

    /**
     * 查询国际机票订单列表
     * 
     * @param iflightOrder 国际机票订单
     * @return 国际机票订单
     */
    @Override
    public List<IflightOrder> selectIflightOrderList(IflightOrder iflightOrder)
    {
        return iflightOrderMapper.selectIflightOrderList(iflightOrder);
    }

    /**
     * 新增国际机票订单
     * 
     * @param iflightOrder 国际机票订单
     * @return 结果
     */
    @Override
    public int insertIflightOrder(IflightOrder iflightOrder)
    {
        return iflightOrderMapper.insertIflightOrder(iflightOrder);
    }

    /**
     * 修改国际机票订单
     * 
     * @param iflightOrder 国际机票订单
     * @return 结果
     */
    @Override
    public int updateIflightOrder(IflightOrder iflightOrder)
    {
        return iflightOrderMapper.updateIflightOrder(iflightOrder);
    }

    /**
     * 批量删除国际机票订单
     * 
     * @param ids 需要删除的国际机票订单ID
     * @return 结果
     */
    @Override
    public int deleteIflightOrderByIds(Long[] ids)
    {
        return iflightOrderMapper.deleteIflightOrderByIds(ids);
    }

    /**
     * 删除国际机票订单信息
     * 
     * @param id 国际机票订单ID
     * @return 结果
     */
    @Override
    public int deleteIflightOrderById(Long id)
    {
        return iflightOrderMapper.deleteIflightOrderById(id);
    }

    /**
     * 创建国际机票订单
     * */
    @Transactional
    @Override
    public int selectIflightOrder(HttpServletRequest request, IflightOrderVo iflightOrderVo) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        long id = System.currentTimeMillis() / 1000;

        CustomerIdVoApi customerIdVoApi = new CustomerIdVoApi();
        customerIdVoApi.setCustomerName(iflightOrderVo.getCustomerName());
        customerIdVoApi.setCustomerCard(iflightOrderVo.getCustomerCard());
        customerIdVoApi.setCustomerPhone(iflightOrderVo.getCustomerPhone());
        CustomerIdVoApi tmpCustomerIdVoApi = remoteCustomerService.customerIdApi(customerIdVoApi);
        Long orderNum = System.currentTimeMillis() / 1000;

        IflightOrder iflightOrder = new IflightOrder();
        iflightOrder.setId(id); //主键
        iflightOrder.setOrderid(orderNum);
        iflightOrder.setPlatformstate(1l);
        iflightOrder.setIsleg("false");

        if (iflightOrderVo.getLatestTicketingTime() != null){
            iflightOrder.setLatestTicketingTime(format.parse(iflightOrderVo.getLatestTicketingTime()));
        }

        iflightOrder.setBigPnr(iflightOrderVo.getPnrVo().getCoding());

        if (iflightOrderVo.getPnrVo().getJourney() != null && iflightOrderVo.getPnrVo().getJourney().size() > 0){
            iflightOrder.setOutboundReturnJourney(FlightOrderConstants.rt.getValue());
        }
        else {
            iflightOrder.setOutboundReturnJourney(FlightOrderConstants.ow.getValue());
        }


        iflightOrder.setPnr(iflightOrderVo.getPnr());

        try {
            iflightOrder.setCreateTime(new Date());
        } catch (Exception e){
            throw new Exception("日期转换错误");
        }

        String token = request.getHeader("token");
        if (token != null && !token.equals("")){
            Employee employee = remoteCustomerService.getLoginEmployeeByToken(token).getData();
            iflightOrder.setCreatoremployeeid(employee.getEmployeeId());
            iflightOrder.setSource("Crm");
        }
        else {
            iflightOrder.setCreatoremployeeid(10l);
            iflightOrder.setSource(iflightOrderVo.getSource());
        }
        iflightOrder.setPaystatus("false");
        iflightOrder.setStatus(FlightOrderConstants.Unpaid.getValue());
        iflightOrder.setOutticketstatus("false");
        iflightOrder.setChangerule(iflightOrderVo.getRefundRebook());
        iflightOrder.setContactemail(iflightOrderVo.getEmail());
        iflightOrder.setContactmobile(iflightOrderVo.getPhone());
        iflightOrder.setContactname(iflightOrderVo.getContact());
        iflightOrder.setMembercardid(tmpCustomerIdVoApi.getCustomerCard());
        iflightOrder.setAutooutticketstatus(0l);
        iflightOrder.setIsdelete("false");
        iflightOrder.setCustomerId(tmpCustomerIdVoApi.getCustomerId());
        int i = iflightOrderMapper.insertIflightOrder(iflightOrder);
        if (i > 0){
            if (iflightOrderVo.getPnrVo().getTravelerVoList() != null &&
                    iflightOrderVo.getPnrVo().getTravelerVoList().size() > 0){
                for (TravelerVo travelerVo : iflightOrderVo.getPnrVo().getTravelerVoList()) {
                    IflightPassenger iflightPassenger = new IflightPassenger();
                    iflightPassenger.setOrderid(id);

                    //成人
                    if (travelerVo.getType().equals("成人")){
                        if (iflightOrderVo.getAldultPrice() != null && !iflightOrderVo.getAldultPrice().equals("")){
                            iflightPassenger.setSettleamount(new BigDecimal(iflightOrderVo.getAldultPrice()));
                            iflightPassenger.setPassengertype(1l);
                        }
                    }
                    //儿童
                    else if (travelerVo.getType().equals("儿童")){
                        if (iflightOrderVo.getChildPrice() != null && !iflightOrderVo.getChildPrice().equals("")){
                            iflightPassenger.setSettleamount(new BigDecimal(iflightOrderVo.getChildPrice()));
                            iflightPassenger.setPassengertype(2l);
                        }
                    }
                    //婴儿
                    else if (travelerVo.getType().equals("婴儿")){
                        if (iflightOrderVo.getBabyPrice() != null && !iflightOrderVo.getBabyPrice().equals("")){
                            iflightPassenger.setSettleamount(new BigDecimal(iflightOrderVo.getBabyPrice()));
                            iflightPassenger.setPassengertype(3l);
                        }
                    }

                    try {
                        iflightOrder.setCreateTime(new Date());
                    } catch (Exception e){
                        throw new Exception("日期转换错误");
                    }
                    iflightPassenger.setDepartureCity(travelerVo.getDepartureCity());
                    iflightPassenger.setArrivalCity(travelerVo.getArrivalCity());
                    iflightPassenger.setFirstname(travelerVo.getName().substring(1));
                    iflightPassenger.setLastname(travelerVo.getName().substring(0, 1));
                    iflightPassenger.setCountryid(travelerVo.getCitizenship());
                    if (travelerVo.getSex().equals("男")){
                        iflightPassenger.setSex("male");
                    }
                    else if (travelerVo.getSex().equals("女")){
                        iflightPassenger.setSex("female");
                    }

                    iflightPassenger.setMobile(travelerVo.getPhone());
                    iflightPassenger.setIdtype(travelerVo.getIdtype());
                    iflightPassenger.setIdno(travelerVo.getIdno());
                    if (travelerVo.getDocumentsDate() != null){
                        iflightPassenger.setIdvaliddate(dateFormat.parse(travelerVo.getDocumentsDate()));
                    }

                    if (travelerVo.getBirthday() != null){
                        iflightPassenger.setBirthday(dateFormat.parse(travelerVo.getBirthday()));
                    }

                    if (token != null && !token.equals("")){
                        Employee employee = remoteCustomerService.getLoginEmployeeByToken(token).getData();
                        iflightPassenger.setCreateemployeeid(employee.getEmployeeId());
                    }
                    else {
                        iflightPassenger.setCreateemployeeid(10l);
                    }

                    iflightPassenger.setAirliner(iflightOrderVo.getPnrVo().getOutbound().get(0).getAirline());
                    iflightPassenger.setFlightNo(iflightOrderVo.getPnrVo().getOutbound().get(0).getFlightNumber());
                    if (iflightOrderVo.getPnrVo().getOutbound().get(0).getDepartureTime() != null){
                        iflightPassenger.setDepartureTime(format.parse(iflightOrderVo.getPnrVo().getOutbound().get(0).getDepartureTime()));
                    }

                    if (iflightOrderVo.getPnrVo().getOutbound().get(0).getArrivalTime() != null){
                        iflightPassenger.setArrivalTime(format.parse(iflightOrderVo.getPnrVo().getOutbound().get(0).getArrivalTime()));
                    }

                    iflightPassenger.setCabin(iflightOrderVo.getPnrVo().getOutbound().get(0).getPosition());
                    iflightPassenger.setFlightType(FlightOrderConstants.outbound.getValue());
                    iflightPassenger.setDepartureCity(iflightOrderVo.getPnrVo().getOutbound().get(0).getSetOff());
                    iflightPassenger.setArrivalCity(iflightOrderVo.getPnrVo().getOutbound().get(0).getArrive());

                    if (iflightPassenger.getCountryid() == null || iflightPassenger.getCountryid().equals("")){
                        iflightPassenger.setCountryid("中国");
                    }
                    int passenger = iflightPassengerMapper.insertIflightPassenger(iflightPassenger);
                    if (passenger <= 0){
                        throw new Exception(travelerVo.getName() + "，数据创建失败(去程)");
                    }

                    if (iflightOrder.getOutboundReturnJourney().equals(FlightOrderConstants.rt.getValue())){
                        iflightPassenger.setAirliner(iflightOrderVo.getPnrVo().getJourney().get(0).getAirline());
                        iflightPassenger.setFlightNo(iflightOrderVo.getPnrVo().getJourney().get(0).getFlightNumber());
                        if (iflightOrderVo.getPnrVo().getJourney().get(0).getDepartureTime() != null){
                            iflightPassenger.setDepartureTime(format.parse(iflightOrderVo.getPnrVo().getJourney().get(0).getDepartureTime()));
                        }

                        if (iflightOrderVo.getPnrVo().getJourney().get(0).getArrivalTime() != null){
                            iflightPassenger.setArrivalTime(format.parse(iflightOrderVo.getPnrVo().getJourney().get(0).getArrivalTime()));
                        }

                        iflightPassenger.setCabin(iflightOrderVo.getPnrVo().getJourney().get(0).getPosition());
                        iflightPassenger.setFlightType(FlightOrderConstants.journey.getValue());
                        iflightPassenger.setDepartureCity(iflightOrderVo.getPnrVo().getJourney().get(0).getSetOff());
                        iflightPassenger.setArrivalCity(iflightOrderVo.getPnrVo().getJourney().get(0).getArrive());
                        passenger = iflightPassengerMapper.insertIflightPassenger(iflightPassenger);
                        if (passenger <= 0){
                            throw new Exception(travelerVo.getName() + "，数据创建失败（返程）");
                        }
                    }
                }
            }
            IflightPayment iflightPayment = new IflightPayment();
            iflightPayment.setOrderid(id);
            iflightPayment.setJsjid(tmpCustomerIdVoApi.getCustomerId());

            try {
                iflightPayment.setCreateTime(new Date());
            } catch (Exception e){
                throw new Exception("日期转换错误");
            }

            iflightPayment.setJsjname(tmpCustomerIdVoApi.getCustomerName());
            iflightPayment.setJsjcardnum(tmpCustomerIdVoApi.getCustomerCard());
            int payment = iflightPaymentMapper.insertIflightPayment(iflightPayment);
            if (payment <= 0){
                throw new Exception("创建支付信息失败");
            }

            if (iflightOrderVo.getWhetherBill().equals("true")){
                IflightOrderInvoice iflightOrderInvoice = new IflightOrderInvoice();
                iflightOrderInvoice.setOrderid(id);
                iflightOrderInvoice.setInvoicetitle(iflightOrderVo.getInvoice());
                iflightOrderInvoice.setVatno(iflightOrderVo.getCoordinatesgd());
                if (iflightOrderVo.getInvoiceAmount() != null && !iflightOrderVo.getInvoiceAmount().equals("")){
                    iflightOrderInvoice.setInvoiceamont(Long.valueOf(iflightOrderVo.getInvoiceAmount()));
                }

                iflightOrderInvoice.setEmail(iflightOrderVo.getEmail());
                iflightOrderInvoice.setPhone(iflightOrderVo.getTelephone());
                iflightOrderInvoice.setUsername(iflightOrderVo.getContact());
                iflightOrderInvoice.setBankName(iflightOrderVo.getBankName());
                iflightOrderInvoice.setAddress(iflightOrderVo.getAddress());
                iflightOrderInvoice.setBankAccount(iflightOrderVo.getAccount());
                int invoice = iflightOrderInvoiceMapper.insertIflightOrderInvoice(iflightOrderInvoice);
                if (invoice <= 0){
                    throw new Exception("发票信息创建失败");
                }
            }

//            redisService.setCacheObject(FLIGHT + tmpCustomerIdVoApi.getCustomerId() + ORDER + orderNum, JSON.toJSON(iflightOrder), 60 * 3000L, TimeUnit.SECONDS);

            Date date = new Date();
            String newDate = format.format(date);
            String messageContent = "您在" + newDate + "，预定从" + iflightOrderVo.getPnrVo().getOutbound().get(0).getSetOff() + "到" +iflightOrderVo.getPnrVo().getOutbound().get(0).getArrive() + "的机票，请在规定时间内支付，以免影响您的日程";
            Map<String,String> map = new HashMap<>();
            map.put("customerId", tmpCustomerIdVoApi.getCustomerId().toString());
            map.put("messageContent", messageContent);
            map.put("businessType", BusinessTypeConstants.flight.getValue());
            map.put("businessOrderId", orderNum.toString());
            remoteCustomerService.addCustomerMessage(map);

            return 1;
        }
        else {
            throw new Exception("国际机票订单创建失败");
        }
    }

    /**
     * pnr导入
     * */
    @Override
    public PNRVo selectPNR(String pnr) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        MoQueryOrderRequest moRequest = new MoQueryOrderRequest();
        moRequest.OrderID = pnr;
        MoQueryOrderResponse moQueryOrderResponse = linkStar._QueryOrderInfo(moRequest);
        if (moQueryOrderResponse != null){
            PNRVo pnrVo = new PNRVo();
            pnrVo.setPnr(pnr);
            pnrVo.setCoding(moQueryOrderResponse.bigPnr);
            pnrVo.setPNRContent(moQueryOrderResponse.xElement);

            List<TmpOutboundVo> outbound = new ArrayList<>();
            if (moQueryOrderResponse.ListGoSegment != null && moQueryOrderResponse.ListGoSegment.size() > 0){
                for (MoSegment moSegment : moQueryOrderResponse.ListGoSegment) {
                    TmpOutboundVo tmpOutboundVo = new TmpOutboundVo();
                    String airliner = airlinerMapper.queryAirlinerByAirlinerId(moSegment.Airline);
                    if (airliner != null && !airliner.equals("")){
                        tmpOutboundVo.setAirline(airliner);
                    }
                    else {
                        tmpOutboundVo.setAirline(moSegment.Airline);
                    }
                    Airport airportSetOff = airportMapper.airportName(moSegment.OrgAirport);
                    if (airportSetOff != null){
                        tmpOutboundVo.setSetOff(airportSetOff.getAirportName());
                        tmpOutboundVo.setSetOffCity(airportSetOff.getAirportCityName());
                    }

                    tmpOutboundVo.setSetOffTerminal(moSegment.orgTerminal);

                    Airport airportArrive = airportMapper.airportName(moSegment.DstAirport);
                    if (airportArrive != null){
                        tmpOutboundVo.setArrive(airportArrive.getAirportName());
                        tmpOutboundVo.setArriveCity(airportArrive.getAirportCityName());
                    }

                    tmpOutboundVo.setArriveTerminal(moSegment.dstTerminal);

                    tmpOutboundVo.setFlightNumber(moSegment.FlightNo);
                    if (moSegment.DepDate != null){
                        tmpOutboundVo.setDepartureTime(format.format(moSegment.DepDate));
                    }

                    if (moSegment.ArrDate != null){
                        tmpOutboundVo.setArrivalTime(format.format(moSegment.ArrDate));
                    }
                    tmpOutboundVo.setPosition(moSegment.Cabin);
                    outbound.add(tmpOutboundVo);
                }
            }
            else {
                throw new Exception("没有去程信息");
            }
            pnrVo.setOutbound(outbound);

            List<TmpOutboundVo> journey = new ArrayList<>();
            if (moQueryOrderResponse.ListBackSegment != null && moQueryOrderResponse.ListBackSegment.size() > 0){
                for (MoSegment moSegment : moQueryOrderResponse.ListBackSegment) {
                    TmpOutboundVo tmpOutboundVo = new TmpOutboundVo();
                    String airliner = airlinerMapper.queryAirlinerByAirlinerId(moSegment.Airline);
                    if (airliner != null && !airliner.equals("")){
                        tmpOutboundVo.setAirline(airliner);
                    }
                    else {
                        tmpOutboundVo.setAirline(moSegment.Airline);
                    }

                    tmpOutboundVo.setSetOff(moSegment.orgTerminal);
                    tmpOutboundVo.setArrive(moSegment.dstTerminal);
                    tmpOutboundVo.setFlightNumber(moSegment.FlightNo);
                    if (moSegment.DepDate != null){
                        tmpOutboundVo.setDepartureTime(format.format(moSegment.DepDate));
                    }

                    if (moSegment.ArrDate != null){
                        tmpOutboundVo.setArrivalTime(format.format(moSegment.ArrDate));
                    }
                    tmpOutboundVo.setPosition(moSegment.Cabin);
                    journey.add(tmpOutboundVo);
                }
            }
            pnrVo.setJourney(journey);

            List<TravelerVo> travelerVoList = new ArrayList<>();
            if (moQueryOrderResponse.ListMoPassenger != null && moQueryOrderResponse.ListMoPassenger.size() > 0){
                for (MoPassenger moPassenger : moQueryOrderResponse.ListMoPassenger) {
                    IDCardUtil idCardUtil = new IDCardUtil();
                    int age = 0;
                    if (moPassenger.licenseNum != null){
                        char str = '/';
                        if (!moPassenger.licenseNum.contains(String.valueOf(str)))
                            age = idCardUtil.getAgeByIdCard(moPassenger.licenseNum);
                    }

                    String birthday = null;
                    if (moPassenger.licenseNum != null){
                        char str = '/';
                        if (!moPassenger.licenseNum.contains(String.valueOf(str)))
                            birthday = idCardUtil.getBirthFormatByIdCard(moPassenger.licenseNum);
                    }


                    TravelerVo travelerVo = new TravelerVo();
                    travelerVo.setName(moPassenger.PassengerName);
                    if (age > 12){
                        travelerVo.setType("成人");
                    }
                    else if (age <= 12 && age > 2){
                        travelerVo.setType("儿童");
                    }
                    else if (age <= 2){
                        travelerVo.setType("婴儿");
                    }

                    if (moPassenger.Sex){
                        travelerVo.setSex("男");
                    }
                    else {
                        travelerVo.setSex("女");
                    }

                    travelerVo.setBirthday(birthday);
                    travelerVo.setIdno(moPassenger.licenseNum);
                    travelerVo.setTicketNum(moPassenger.TicketNo);
                    travelerVoList.add(travelerVo);
                }
            }
            pnrVo.setTravelerVoList(travelerVoList);
            return pnrVo;
        }
        else {
            throw new Exception("没有对应信息");
        }
    }

    /**
     * 国际机票订单列表
     * */
    @Override
    public List<IflightOrder> tmpIflightOrderVoList(InternationalityVo internationalityVo) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        CustomerIdVoApi customerIdVoApi = new CustomerIdVoApi();
        if (internationalityVo.customerCard != null && !internationalityVo.customerCard.equals("")){
            customerIdVoApi.setCustomerCard(internationalityVo.customerCard);
        }
        if (internationalityVo.customerName != null && !internationalityVo.customerName.equals("")){
            customerIdVoApi.setCustomerName(internationalityVo.customerName);
        }
        if (customerIdVoApi != null){
            customerIdVoApi = remoteCustomerService.customerIdApi(customerIdVoApi);
        }
        if (customerIdVoApi != null && customerIdVoApi.getCustomerId() != null && customerIdVoApi.getCustomerId() != 0){
            internationalityVo.customerId = customerIdVoApi.getCustomerId();
        }
        if (internationalityVo.bookingStaff != null && !internationalityVo.bookingStaff.equals("")){
            Map<String, Object> map = new HashMap<>();
            map.put("name", internationalityVo.bookingStaff);
            List<Long> longList = remoteCustomerService.employeeIdList(map);
            internationalityVo.longList = longList;
        }

        if (internationalityVo.flightCrew != null && !internationalityVo.flightCrew.equals("")){
            internationalityVo.surname = internationalityVo.flightCrew.substring(0, 1);
            internationalityVo.name = internationalityVo.flightCrew.substring(1);
        }

        if (internationalityVo.flightCrew != null && !internationalityVo.flightCrew.equals("") ||
                internationalityVo.idNumber != null && !internationalityVo.idNumber.equals("") ||
                internationalityVo.ticketNum != null && !internationalityVo.ticketNum.equals("")){
            List<IflightPassenger> iflightPassengers = iflightPassengerMapper.iflightPassengerList(internationalityVo);
            if (iflightPassengers != null && iflightPassengers.size() > 0){
                for (IflightPassenger iflightPassenger : iflightPassengers) {
                    internationalityVo.idList.add(iflightPassenger.getOrderid());
                }
            }
            else {
                throw new Exception("没有符合条件的订单明细");
            }
        }
        IflightOrder iflightOrderObj = new IflightOrder();
        List<IflightOrder> iflightOrders = iflightOrderMapper.selectIflightOrderList(iflightOrderObj);

//        List<IflightOrder> iflightOrders = iflightOrderMapper.selectIflightOrderVoList(internationalityVo);

        if (iflightOrders != null && iflightOrders.size() > 0){
            for (IflightOrder iflightOrder : iflightOrders) {
                List<IflightPassenger> iflightPassengers = iflightPassengerMapper.selectPassenger(iflightOrder.getOrderid());
                iflightOrder.setPassengerCount(iflightPassengers.size());

                if (iflightPassengers.size() > 0){
                    String passenger = "";
                    for (int i = 0 ; i < iflightPassengers.size() ; i++) {
                        String name = iflightPassengers.get(i).getLastname() + iflightPassengers.get(i).getFirstname();
                        if (i == 0){
                            passenger = name;
                        }
                        else {
                            passenger = passenger + "," + name;
                        }
                    }
                    iflightOrder.setPassenger(passenger);

                    if (iflightPassengers.get(0).getDepartureTime() != null &&
                            !iflightPassengers.get(0).getDepartureTime().equals("") &&
                            iflightPassengers.get(0).getArrivalTime() != null &&
                            !iflightPassengers.get(0).getArrivalTime().equals("")){

                        String departureTime = format.format(iflightPassengers.get(0).getDepartureTime());
                        String ArrivalTime = format.format(iflightPassengers.get(0).getArrivalTime());
                        iflightOrder.setTime(departureTime + "-" + ArrivalTime);
                    }
                }

                Map<String, Object> map = new HashMap<>();
                map.put("id", iflightOrder.getCreatoremployeeid());
                Employee employee = remoteCustomerService.employeeNameList(map);
                iflightOrder.setReserveName(employee.getEmployeeName());
            }
            return iflightOrders;
        }
        else {
            throw new Exception("没有符合条件的订单数据");
        }
    }

    /**
     * 国际机票详情
     * */
    @Override
    public IflightOrderVo selectIflightPassengerById(Long id) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        IflightOrderVo iflightOrderVo = new IflightOrderVo();

        IflightOrder iflightOrder = iflightOrderMapper.selectIflightOrderById(id);
        List<IflightPassenger> iflightPassengers = iflightPassengerMapper.selectPassenger(id);

        CustomerIdVoApi customerIdVoApi = new CustomerIdVoApi();
        customerIdVoApi.setCustomerId(iflightOrder.getCustomerId());
        customerIdVoApi = remoteCustomerService.customerIdApi(customerIdVoApi);

        if (customerIdVoApi != null){
            iflightOrderVo.setCustomerName(customerIdVoApi.getCustomerName());
            iflightOrderVo.setCustomerPhone(customerIdVoApi.getCustomerPhone());
            iflightOrderVo.setCustomerCard(customerIdVoApi.getCustomerCard());
        }

        if (iflightPassengers != null && iflightPassengers.size() > 0){
            for (IflightPassenger iflightPassenger : iflightPassengers) {
                if (iflightOrderVo.getAldultPrice() == null && iflightPassenger.getPassengertype() == 1){
                    iflightOrderVo.setAldultPrice(iflightPassenger.getSettleamount().toString());
                }
                else if (iflightOrderVo.getChildPrice() == null && iflightPassenger.getPassengertype() == 2){
                    iflightOrderVo.setChildPrice(iflightPassenger.getSettleamount().toString());
                }
                else if (iflightOrderVo.getBabyPrice() == null && iflightPassenger.getPassengertype() == 3){
                    iflightOrderVo.setBabyPrice(iflightPassenger.getSettleamount().toString());
                }
            }
        }

        if (iflightOrder.getLatestTicketingTime() != null){
            iflightOrderVo.setLatestTicketingTime(format.format(iflightOrder.getLatestTicketingTime()));
        }

        IflightOrderInvoice iflightOrderInvoice = iflightOrderInvoiceMapper.iflightOrderInvoiceList(id);
        if (iflightOrderInvoice != null){
            iflightOrderVo.setWhetherBill("true");
            iflightOrderVo.setInvoice(iflightOrderInvoice.getInvoicetitle());
            iflightOrderVo.setTelephone(iflightOrderInvoice.getTelephone());
            iflightOrderVo.setBankName(iflightOrderInvoice.getBankName());
            iflightOrderVo.setAddress(iflightOrderInvoice.getAddress());
            iflightOrderVo.setAccount(iflightOrderInvoice.getBankAccount());
            iflightOrderVo.setEmail(iflightOrderInvoice.getEmail());

            if (iflightOrderInvoice.getInvoiceamont() != null){
                iflightOrderVo.setInvoiceAmount(iflightOrderInvoice.getInvoiceamont().toString());
            }

            iflightOrderVo.setContact(iflightOrderInvoice.getUsername());
            iflightOrderVo.setPhone(iflightOrderInvoice.getPhone());

            if (iflightOrderInvoice.getBillType().equals("company")){
                iflightOrderVo.setInvoiceType("公司");
            }
            else if (iflightOrderInvoice.getBillType().equals("personal")){
                iflightOrderVo.setInvoiceType("个人");
            }

            iflightOrderVo.setCoordinatesgd(iflightOrderInvoice.getVatno());
        }
        else {
            iflightOrderVo.setWhetherBill("false");
        }

        iflightOrderVo.setRefundRebook(iflightOrder.getChangerule());

        PNRVo pnrVo = new PNRVo();
        pnrVo.setCoding(iflightOrder.getBigPnr());
        pnrVo.setPnr(iflightOrder.getPnr());

        List<TmpOutboundVo> outbound = new ArrayList<>();
        List<TmpOutboundVo> journey = new ArrayList<>();
        List<TravelerVo> travelerVoList = new ArrayList<>();
        for (IflightPassenger iflightPassenger : iflightPassengers) {
            TmpOutboundVo tmpOutboundVo = new TmpOutboundVo();
            tmpOutboundVo.setAirline(iflightPassenger.getAirliner());
            tmpOutboundVo.setSetOff(iflightPassenger.getDepartureTerminal());
            tmpOutboundVo.setArrive(iflightPassenger.getArrivalTerminal());
            tmpOutboundVo.setFlightNumber(iflightPassenger.getFlightNo());

            if (iflightPassenger.getDepartureTime() != null){
                tmpOutboundVo.setDepartureTime(format.format(iflightPassenger.getDepartureTime()));
            }

            if (iflightPassenger.getArrivalTime() != null){
                tmpOutboundVo.setArrivalTime(format.format(iflightPassenger.getArrivalTime()));
            }

            tmpOutboundVo.setPosition(iflightPassenger.getCabin());

            if (iflightPassenger.getFlightType() != null && iflightPassenger.getFlightType().equals(FlightOrderConstants.outbound.getValue())){
                outbound.add(tmpOutboundVo);
            }
            else if (iflightPassenger.getFlightType() != null && iflightPassenger.getFlightType().equals(FlightOrderConstants.journey.getValue())){
                journey.add(tmpOutboundVo);
            }



            TravelerVo travelerVo = new TravelerVo();
            travelerVo.setName(iflightPassenger.getLastname() + iflightPassenger.getFirstname());

            if (iflightPassenger.getPassengertype() == 1){
                travelerVo.setType("成人");
            }
            else if (iflightPassenger.getPassengertype() == 2){
                travelerVo.setType("儿童");
            }
            else if (iflightPassenger.getPassengertype() == 3){
                travelerVo.setType("婴儿");
            }

            if (iflightPassenger.getSex().equals("male")){
                travelerVo.setSex("男");
            }
            else if (iflightPassenger.getSex().equals("female")){
                travelerVo.setSex("女");
            }

            if (iflightPassenger.getBirthday() != null){
                travelerVo.setBirthday(format.format(iflightPassenger.getBirthday()));
            }

            travelerVo.setCitizenship(iflightPassenger.getCountryid());
            travelerVo.setPhone(iflightPassenger.getMobile());

            if (iflightPassenger.getIdvaliddate() != null){
                travelerVo.setDocumentsDate(format.format(iflightPassenger.getIdvaliddate()));
            }

            travelerVo.setIdno(iflightPassenger.getIdno());
            travelerVo.setIdtype(iflightPassenger.getIdtype());
            travelerVo.setTicketNum(iflightPassenger.getTicketnumber());
        }

        pnrVo.setOutbound(outbound);
        pnrVo.setJourney(journey);
        pnrVo.setTravelerVoList(travelerVoList);

        iflightOrderVo.setPnrVo(pnrVo);
        iflightOrderVo.setPnr(iflightOrder.getPnr());
        iflightOrderVo.setSource(iflightOrder.getSource());

        return iflightOrderVo;
    }

    /**
     * 国际机票支付页
     * */
    @Override
    public TmpIflightOrderVo selectTmpIflightOrderVo(Long id) throws Exception {
        IflightOrder iflightOrder = iflightOrderMapper.selectIflightOrderById(id);
        List<IflightPassenger> iflightPassengers = iflightPassengerMapper.selectPassenger(id);
        if (iflightOrder != null){
            TmpIflightOrderVo tmpIflightOrderVo = new TmpIflightOrderVo();
            tmpIflightOrderVo.setOrderId(iflightOrder.getId());

            List<TmpIflightOrder> tmpIflightOrderList = new ArrayList<>();
            if (iflightPassengers.size() > 0){

                int count = 0;
                BigDecimal amont = new BigDecimal(0);
                for (IflightPassenger iflightPassenger : iflightPassengers) {
                    TmpIflightOrder tmpIflightOrder = new TmpIflightOrder();
                    //单程
                    if (iflightOrder.getOutboundReturnJourney().equals(FlightOrderConstants.ow.getValue())){
                        tmpIflightOrder.setOrderNum(iflightOrder.getOrderid().toString());
                        tmpIflightOrder.setClassification("单程");
                        tmpIflightOrder.setDescribe(iflightPassenger.getDepartureCity() + "-" + iflightPassenger.getArrivalCity() + "-" + iflightPassenger.getFlightNo());
                        tmpIflightOrder.setPrice(iflightPassenger.getSettleamount().toString());
                        amont = iflightPassenger.getSettleamount();
                        tmpIflightOrderList.add(tmpIflightOrder);
                        break;
                    }
                    //往返
                    else if (iflightOrder.getOutboundReturnJourney().equals(FlightOrderConstants.rt.getValue())){
                        //往返-去程
                        if (count != 1 && iflightPassenger.getFlightType().equals(FlightOrderConstants.outbound.getValue())){
                            count = 1;
                            tmpIflightOrder.setOrderNum(iflightOrder.getOrderid().toString());
                            tmpIflightOrder.setClassification("去程");
                            tmpIflightOrder.setDescribe(iflightPassenger.getDepartureCity() + "-" + iflightPassenger.getArrivalCity() + "-" + iflightPassenger.getFlightNo());
                            tmpIflightOrder.setPrice(iflightPassenger.getSettleamount().toString());
                            amont = amont.add(iflightPassenger.getSettleamount());
                            tmpIflightOrderList.add(tmpIflightOrder);
                        }
                        //往返-返程
                        else if (count != 2 && iflightPassenger.getFlightType().equals(FlightOrderConstants.journey.getValue())){
                            count = 2;
                            tmpIflightOrder.setOrderNum(iflightOrder.getOrderid().toString());
                            tmpIflightOrder.setClassification("返程");
                            tmpIflightOrder.setDescribe(iflightPassenger.getDepartureCity() + "-" + iflightPassenger.getArrivalCity() + "-" + iflightPassenger.getFlightNo());
                            tmpIflightOrder.setPrice(iflightPassenger.getSettleamount().toString());
                            amont = amont.add(iflightPassenger.getSettleamount());
                            tmpIflightOrderList.add(tmpIflightOrder);
                        }
                    }
                }
                tmpIflightOrderVo.setTmpIflightOrderList(tmpIflightOrderList);
                tmpIflightOrderVo.setTotalCost(amont.toString());

                iflightOrder.setTicamount(amont);
                iflightOrderMapper.updateAmount(iflightOrder);
            }

            tmpIflightOrderVo.setCustomerId(iflightOrder.getCustomerId());
            R<Long> longR = remoteCustomerService.selectAvailableGoldByCustomerId(iflightOrder.getCustomerId());
            if (longR.getData() != null && longR.getData() != 0){
                tmpIflightOrderVo.setGold(longR.getData().toString());
            }
            else {
                tmpIflightOrderVo.setGold("0");
            }
            return tmpIflightOrderVo;
        }
        else {
            throw new Exception("无效的订单id");
        }
    }

    /**
     * 国际机票支付
     * */
    @Override
    public PayResultVo internationalTicketPay(HttpServletRequest request, InternationalPayVo internationalPayVo) throws Exception {
        internationalPayVo.setMoneyAmout("0.1");

        String token = request.getHeader("token");
        Employee employee = remoteCustomerService.getLoginEmployeeByToken(token).getData();
        if (employee == null){
            throw new Exception("登录已过期");
        }

        if (internationalPayVo.getPayType() != null && !internationalPayVo.getPayType().equals("")){
            PayResultVo payResultVo = new PayResultVo();
            payResultVo.setCode(0l);

            Customer customer = remoteCustomerService.getCustomerId(internationalPayVo.getCustomerId()).getData();
            if (customer == null){
                throw new Exception("无效的会员编号");
            }

            BankCard bankCard = null;
            if (internationalPayVo.getBankCardId() != null && internationalPayVo.getBankCardId() != 0){
                bankCard = remoteCustomerService.selectBankCardBytBankCardId(internationalPayVo.getBankCardId());
                if (bankCard == null){
                    throw new Exception("没有银行卡记录");
                }
            }

            IflightOrder iflightOrder = new IflightOrder();
            iflightOrder.setId(internationalPayVo.getOrderId());
            iflightOrder.setPaymentMethod(internationalPayVo.getPayType());
            iflightOrderMapper.updateIflightOrder(iflightOrder);

            if (internationalPayVo.getAmount() != null && internationalPayVo.getAmount().compareTo(new BigDecimal(0)) > 0){
                internationalPayVo.setMoneyAmout((new BigDecimal(internationalPayVo.getMoneyAmout()).subtract(internationalPayVo.getAmount())).toString());

                iflightOrder.setAmount(internationalPayVo.getAmount());
                int i = iflightOrderMapper.updateIflightOrder(iflightOrder);
                if (i <= 0){
                    throw new Exception("修改订单预留款失败");
                }

                DepositBusinessApi depositBusiness = new DepositBusinessApi();
                depositBusiness.setRemark("国际机票支付");
                depositBusiness.setState("false");
                depositBusiness.setBusinessType(EmHelper.businessType.FLIGHT.getValue());
                depositBusiness.setOperatorId(employee.getEmployeeId());
                depositBusiness.setOrdersourceid(internationalPayVo.getType());
                depositBusiness.setCustomerId(internationalPayVo.getCustomerId());
                depositBusiness.setDetailamount(internationalPayVo.getAmount());
                depositBusiness.setChangetype(2l);
                depositBusiness.setLockState("false");
                depositBusiness.setOrderId(Long.valueOf(internationalPayVo.getOrderNum()));
                depositBusiness.setDrawState("false");
                Long aLong = remoteCustomerService.addReserveMoney(depositBusiness);
                if (aLong <= 0){
                    throw new Exception("添加预留款记录失败");
                }

                Map<String, Object> map = new HashMap<>();
                map.put("id", aLong);
                map.put("remark", "国际机票支付");
                boolean b = remoteCustomerService.manageAudit(map);
                if (!b){
                    throw new Exception("审核失败，请进行人工审核");
                }
            }

            //信用卡支付
            if (internationalPayVo.getPayType().equals(EmHelper.cardType.CREDIT_CARD.getValue())){
                BankPayInfoApi bankPayInfo = new BankPayInfoApi();
                bankPayInfo.setJsjOrderId(internationalPayVo.getOrderNum());
                bankPayInfo.setMoneyAmout(internationalPayVo.getMoneyAmout());
                CustomerApi customerApi = new CustomerApi();
                BeanUtils.copyProperties(customer, customerApi);
                bankPayInfo.setCustomer(customerApi);

                if (bankCard != null && !bankCard.getCardType().equals(EmHelper.cardType.CREDIT_CARD.getValue())){
                    throw new Exception("不支持的银行卡");
                }
                BankCardApi bankCardApi = new BankCardApi();
                BeanUtils.copyProperties(bankCard, bankCardApi);
                bankPayInfo.setCard(bankCardApi);
                bankPayInfo.setPayType(internationalPayVo.getPayWay());
                YeeBaoResultApi yeeBaoResultApi = remotePayService.CreditSale(bankPayInfo);
                if (yeeBaoResultApi.getCode().equals("1")){
                    payResult(internationalPayVo, "true", "0", yeeBaoResultApi.getTrxId());
                    payResultVo.setMsg("支付成功");
                }
                else {
                    payResult(internationalPayVo, "false", "0", null);
                    payResultVo.setCode(Long.valueOf(yeeBaoResultApi.getCode()));
                    payResultVo.setMsg(yeeBaoResultApi.getErrorMsg());
                }
            }
            //借记卡
            else if (internationalPayVo.getPayType().equals(EmHelper.cardType.DEBIT_CARD.getValue())){
                BankPayInfoApi bankPayInfo = new BankPayInfoApi();
                bankPayInfo.setJsjOrderId(internationalPayVo.getOrderNum());
                bankPayInfo.setMoneyAmout(internationalPayVo.getMoneyAmout());
                CustomerApi customerApi = new CustomerApi();
                BeanUtils.copyProperties(customer, customerApi);
                bankPayInfo.setCustomer(customerApi);

                if (bankCard != null && !bankCard.getCardType().equals(EmHelper.cardType.DEBIT_CARD.getValue())){
                    throw new Exception("不支持的银行卡");
                }
                BankCardApi bankCardApi = new BankCardApi();
                BeanUtils.copyProperties(bankCard, bankCardApi);
                bankPayInfo.setCard(bankCardApi);
                bankPayInfo.setPayType(internationalPayVo.getPayWay());
                YeeBaoResultApi yeeBaoResultApi = remotePayService.DebitSale(bankPayInfo);
                if (yeeBaoResultApi.getCode().equals("1")){
                    payResult(internationalPayVo, "true", "0", yeeBaoResultApi.getTrxId());
                    payResultVo.setMsg("支付成功");
                }
                else {
                    payResult(internationalPayVo, "false", "0", null);
                    payResultVo.setCode(Long.valueOf(yeeBaoResultApi.getCode()));
                    payResultVo.setMsg(yeeBaoResultApi.getErrorMsg());
                }
            }
            //银联二维码
            else if (internationalPayVo.getPayType().equals(EmHelper.cardType.UnionPayQR.getValue())){
                Map<String, String> map = new HashMap<>();
                map.put("billNo", internationalPayVo.getOrderNum());
                map.put("totalAmount", String.valueOf(new BigDecimal(internationalPayVo.getMoneyAmout()).multiply(new BigDecimal(100)).longValue()));
                map.put("notifyUrl", "http://106.38.39.137:8080/flight/callback/unionPayQRCallback");

                UnionPayQRCodeResponseApi qrCode = remotePayService.getQRCode(map);
                if (qrCode.getErrCode().equals("SUCCESS")){
                    payResultVo.setMsg(qrCode.getBillQRCode());
                }
                else {
                    payResultVo.setMsg(qrCode.getErrMsg());
                }
            }
            //预留款
            else if (internationalPayVo.getPayType().equals(EmHelper.cardType.Reserve_Money.getValue())){
                Long aLong = remoteCustomerService.selectAvailableGoldByCustomerId(internationalPayVo.getCustomerId()).getData();
                if (aLong != null && aLong != 0 && aLong >= Long.valueOf(internationalPayVo.getMoneyAmout())){
                    DepositBusinessApi depositBusinessApi = new DepositBusinessApi();
                    depositBusinessApi.setOperationtime(new Date());
                    depositBusinessApi.setRemark("国际机票消费");
                    depositBusinessApi.setState("notReviewed");
                    depositBusinessApi.setBusinessType(EmHelper.businessType.FLIGHT.getValue());
                    depositBusinessApi.setOperatorId(employee.getEmployeeId());
                    depositBusinessApi.setOrdersourceid(internationalPayVo.getPayWay());
                    depositBusinessApi.setCustomerId(internationalPayVo.getCustomerId());
                    depositBusinessApi.setDetailamount(new BigDecimal(internationalPayVo.getMoneyAmout()));
                    depositBusinessApi.setChangetype(2l);
                    depositBusinessApi.setOperapersonid(employee.getEmployeeId());
                    depositBusinessApi.setOrderId(Long.valueOf(internationalPayVo.getOrderNum()));
                    aLong = remoteCustomerService.addReserveMoney(depositBusinessApi);
                    if (aLong > 0){
                        payResult(internationalPayVo, "true", internationalPayVo.getMoneyAmout(), null);
                        payResultVo.setMsg("支付成功");
                    }
                    else {
                        payResult(internationalPayVo, "false", internationalPayVo.getMoneyAmout(), null);
                        payResultVo.setMsg("支付失败");
                        payResultVo.setCode(1l);
                    }
                }
                else {
                    throw new Exception("预留款金额不足，无法支付");
                }
            }

            return payResultVo;
        }
        else {
            throw new Exception("缺少必要参数");
        }
    }

    /**
     * 国际机票退票详情
     * */
    @Override
    public RefundVo selectRefundDetails(Long id) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        RefundVo refundVo = new RefundVo();
        IflightOrder iflightOrder = iflightOrderMapper.selectIflightOrderById(id);
        List<IflightPassenger> iflightPassengers = iflightPassengerMapper.selectPassenger(id);
        if (iflightOrder != null && iflightPassengers.size() > 0){
            CustomerIdVoApi customerIdVoApi = new CustomerIdVoApi();
            customerIdVoApi.setCustomerId(iflightOrder.getCustomerId());
            customerIdVoApi = remoteCustomerService.customerIdApi(customerIdVoApi);

            if (customerIdVoApi != null){
                refundVo.setCustomerName(customerIdVoApi.getCustomerName());
                refundVo.setCustomerCard(customerIdVoApi.getCustomerCard());
                refundVo.setCardType(customerIdVoApi.getCustomerCardType());
            }

            List<OrderRefundVo> orderRefundVos = new ArrayList<>();
            for (IflightPassenger iflightPassenger : iflightPassengers) {
                if (iflightPassenger.getDepartureCity() != null && !iflightPassenger.getDepartureCity().equals("") &&
                        iflightPassenger.getArrivalCity() != null && !iflightPassenger.getArrivalCity().equals("")){
                    OrderRefundVo orderRefundVo = new OrderRefundVo();
                    orderRefundVo.setPassengerId(iflightPassenger.getPassengerid());
                    orderRefundVo.setName(iflightPassenger.getLastname() + iflightPassenger.getFirstname());
                    orderRefundVo.setVoyage(iflightPassenger.getDepartureCity() + "-->" + iflightPassenger.getArrivalCity());
                    orderRefundVo.setLicenseNumber(iflightPassenger.getIdno());
                    orderRefundVo.setAirline(iflightPassenger.getAirliner());
                    orderRefundVo.setFlightNumber(iflightPassenger.getFlightNo());
                    orderRefundVo.setCabinSeat(iflightPassenger.getCabin());
                    orderRefundVo.setTicketNumber(iflightPassenger.getTicketnumber());
                    if (iflightPassenger.getDepartureTime() != null){
                        orderRefundVo.setDepartureTime(format.format(iflightPassenger.getDepartureTime()));
                    }
                    if (iflightOrder.getTicamount() != null){
                        orderRefundVo.setTotalReceivables(iflightOrder.getTicamount().toString());
                    }
                    if (iflightPassenger.getSettleamount() != null){
                        orderRefundVo.setAmountsPayable(iflightPassenger.getSettleamount().toString());
                    }
                    orderRefundVo.setOutboundORJourney(iflightPassenger.getFlightType());
                    orderRefundVos.add(orderRefundVo);
                }
            }

            refundVo.setOrderRefundVos(orderRefundVos);
            return refundVo;
        }
        else {
            throw new Exception("无效的订单id");
        }
    }

    /**
     * 国际机票退款
     * */
    @Override
    public String refund(HttpServletRequest request, CancelVo cancelVo) throws Exception {
        IflightOrder iflightOrder = iflightOrderMapper.selectIflightOrderById(cancelVo.getId());
        IflightPayment iflightPayment = iflightPaymentMapper.selectIflightPaymentByOrderId(cancelVo.getId());

        String token = request.getHeader("token");
        Employee employee = remoteCustomerService.getLoginEmployeeByToken(token).getData();
        cancelVo.setEmployeeId(employee.getEmployeeId());
        if (employee == null){
            throw new Exception("登录已过期");
        }

        //原路返回
        if (cancelVo.getType() != null && cancelVo.getType().equals(FlightOrderConstants.backtrack.getValue())){

            if (iflightOrder.getAmount() != null && iflightOrder.getAmount().compareTo(new BigDecimal(0)) > 0){
                DepositBusinessApi depositBusiness = new DepositBusinessApi();
                depositBusiness.setRemark("国际机票退票");
                depositBusiness.setState("false");
                depositBusiness.setBusinessType(EmHelper.businessType.FLIGHT.getValue());
                depositBusiness.setOperatorId(employee.getEmployeeId());
                depositBusiness.setOrdersourceid(cancelVo.getPayWay());
                depositBusiness.setCustomerId(iflightOrder.getCustomerId());
                depositBusiness.setDetailamount(iflightOrder.getAmount());
                depositBusiness.setChangetype(1l);
                depositBusiness.setLockState("false");
                depositBusiness.setOrderId(iflightOrder.getOrderid());
                depositBusiness.setDrawState("false");
                Long aLong = remoteCustomerService.addReserveMoney(depositBusiness);
                if (aLong <= 0){
                    throw new Exception("添加预留款记录失败");
                }
            }

            //信用卡
            if (iflightOrder.getPaymentMethod().equals(EmHelper.cardType.CREDIT_CARD.getValue())){
                Map<String, String> map = new HashMap<>();
                map.put("jsjOrderId", iflightOrder.getOrderid().toString());
                map.put("bankTrxId", iflightPayment.getExternalbillno());
                map.put("moneyAmout", cancelVo.getAmount());
                map.put("payType", cancelVo.getPayWay());
                YeeBaoResultApi yeeBaoResultApi = remotePayService.bankCreditRefund(map);
                if (yeeBaoResultApi.getCode().equals("1")){
                    try {
                        cancel(cancelVo, 1);
                    } catch (Exception e){
                        throw new Exception(e.getMessage());
                    }
                    return "退款成功";
                }
                else {
                    throw new Exception(yeeBaoResultApi.getErrorMsg());
                }
            }
            //借记卡
            else if (iflightOrder.getPaymentMethod().equals(EmHelper.cardType.DEBIT_CARD.getValue())){
                Map<String, String> map = new HashMap<>();
                map.put("jsjOrderId", iflightOrder.getOrderid().toString());
                map.put("bankTrxId", iflightPayment.getExternalbillno());
                map.put("moneyAmout", cancelVo.getAmount());
                YeeBaoResultApi yeeBaoResultApi = remotePayService.bankDebitRefund(map);
                if (yeeBaoResultApi.getCode().equals("1")){
                    try {
                        cancel(cancelVo, 1);
                    } catch (Exception e){
                        throw new Exception(e.getMessage());
                    }
                    return "退款成功";
                }
                else {
                    throw new Exception(yeeBaoResultApi.getErrorMsg());
                }
            }
            //银联二维码
            else if (iflightOrder.getPaymentMethod().equals(EmHelper.cardType.UnionPayQR.getValue())){
                Map<String, String> map = new HashMap<>();
                map.put("refundAmount", cancelVo.getAmount());
                map.put("billNo", iflightPayment.getExternalbillno());
                map.put("notifyUrl", "http://106.38.39.137:8080/flight/callback/retreatUnionPayQRCallback");
                UnionPayQRCodeResponseApi unionPayQRCodeResponseApi = remotePayService.qrCodeRefund(map);
                if (unionPayQRCodeResponseApi.getErrCode().equals("SUCCESS")){
                    try {
                        cancel(cancelVo, 0);
                    } catch (Exception e){
                        throw new Exception(e.getMessage());
                    }
                    return "退款成功";
                }
                else {
                    throw new Exception(unionPayQRCodeResponseApi.getErrMsg());
                }
            }
            //预留款
            else if (iflightOrder.getPaymentMethod().equals(EmHelper.cardType.Reserve_Money.getValue())){
                DepositBusinessApi depositBusinessApi = new DepositBusinessApi();
                depositBusinessApi.setOperationtime(new Date());
                depositBusinessApi.setRemark("国际机票退款");
                depositBusinessApi.setState("notReviewed");
                depositBusinessApi.setBusinessType(EmHelper.businessType.FLIGHT.getValue());
                depositBusinessApi.setOperatorId(employee.getEmployeeId());
                depositBusinessApi.setOrdersourceid(cancelVo.getPayWay());
                depositBusinessApi.setCustomerId(iflightOrder.getCustomerId());
                depositBusinessApi.setDetailamount(new BigDecimal(cancelVo.getAmount()));
                depositBusinessApi.setChangetype(1l);
                depositBusinessApi.setOperapersonid(employee.getEmployeeId());
                depositBusinessApi.setOrderId(Long.valueOf(iflightOrder.getOrderid()));
                Long aLong = remoteCustomerService.addReserveMoney(depositBusinessApi);
                if (aLong > 0){
                    try {
                        cancel(cancelVo, 1);
                    } catch (Exception e){
                        throw new Exception(e.getMessage());
                    }
                    return "退款成功";
                }
                else {
                    return "退款失败";
                }
            }
        }
        //预留款
        else if (cancelVo.getType() != null && cancelVo.getType().equals(FlightOrderConstants.reserveMoney.getValue())){
            DepositBusinessApi depositBusinessApi = new DepositBusinessApi();
            depositBusinessApi.setOperationtime(new Date());
            depositBusinessApi.setRemark("国际机票退款");
            depositBusinessApi.setState("notReviewed");
            depositBusinessApi.setBusinessType(EmHelper.businessType.FLIGHT.getValue());
            depositBusinessApi.setOperatorId(employee.getEmployeeId());
            depositBusinessApi.setOrdersourceid(cancelVo.getPayWay());
            depositBusinessApi.setCustomerId(iflightOrder.getCustomerId());
            depositBusinessApi.setDetailamount(new BigDecimal(cancelVo.getAmount()));
            depositBusinessApi.setChangetype(1l);
            depositBusinessApi.setOperapersonid(employee.getEmployeeId());
            depositBusinessApi.setOrderId(Long.valueOf(iflightOrder.getOrderid()));
            Long aLong = remoteCustomerService.addReserveMoney(depositBusinessApi);
            if (aLong > 0){
                try {
                    cancel(cancelVo, 1);
                } catch (Exception e){
                    throw new Exception(e.getMessage());
                }
                return "退款成功";
            }
            else {
                return "退款失败";
            }
        }
        return null;
    }

    /**
     * 国际机票改签
     * */
    @Transactional
    @Override
    public int rebook(HttpServletRequest request, IflightOrderVo iflightOrderVo) throws Exception {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        long id = System.currentTimeMillis() / 1000;

        CustomerIdVoApi customerIdVoApi = new CustomerIdVoApi();
        customerIdVoApi.setCustomerName(iflightOrderVo.getCustomerName());
        customerIdVoApi.setCustomerCard(iflightOrderVo.getCustomerCard());
        customerIdVoApi.setCustomerPhone(iflightOrderVo.getCustomerPhone());
        CustomerIdVoApi tmpCustomerIdVoApi = remoteCustomerService.customerIdApi(customerIdVoApi);
        Long orderNum = System.currentTimeMillis() / 1000;

        IflightOrder iflightOrder = new IflightOrder();
        iflightOrder.setId(id); //主键
        iflightOrder.setOrderid(orderNum);
        iflightOrder.setPlatformstate(1l);
        iflightOrder.setIsleg("false");

        if (iflightOrderVo.getOrderNum() != null && !iflightOrderVo.getOrderNum().equals("")){
            iflightOrder.setOldOrderNum(iflightOrderVo.getOrderNum());
        }

        if (iflightOrderVo.getLatestTicketingTime() != null){
            iflightOrder.setLatestTicketingTime(format.parse(iflightOrderVo.getLatestTicketingTime()));
        }

        iflightOrder.setBigPnr(iflightOrderVo.getPnrVo().getCoding());

        if (iflightOrderVo.getPnrVo().getJourney() != null && iflightOrderVo.getPnrVo().getJourney().size() > 0){
            iflightOrder.setOutboundReturnJourney(FlightOrderConstants.rt.getValue());
        }
        else {
            iflightOrder.setOutboundReturnJourney(FlightOrderConstants.ow.getValue());
        }


        iflightOrder.setPnr(iflightOrderVo.getPnr());

        try {
            iflightOrder.setCreateTime(new Date());
        } catch (Exception e){
            throw new Exception("日期转换错误");
        }

        String token = request.getHeader("token");
        if (token != null && !token.equals("")){
            Employee employee = remoteCustomerService.getLoginEmployeeByToken(token).getData();
            iflightOrder.setCreatoremployeeid(employee.getEmployeeId());
            iflightOrder.setSource("Crm");
        }
        else {
            iflightOrder.setCreatoremployeeid(10l);
            iflightOrder.setSource(iflightOrderVo.getSource());
        }
        iflightOrder.setPaystatus("false");
        iflightOrder.setStatus(FlightOrderConstants.Unpaid.getValue());
        iflightOrder.setOutticketstatus("false");
        iflightOrder.setChangerule(iflightOrderVo.getRefundRebook());
        iflightOrder.setContactemail(iflightOrderVo.getEmail());
        iflightOrder.setContactmobile(iflightOrderVo.getPhone());
        iflightOrder.setContactname(iflightOrderVo.getContact());
        iflightOrder.setMembercardid(tmpCustomerIdVoApi.getCustomerCard());
        iflightOrder.setAutooutticketstatus(0l);
        iflightOrder.setIsdelete("false");
        iflightOrder.setCustomerId(tmpCustomerIdVoApi.getCustomerId());
        int i = iflightOrderMapper.insertIflightOrder(iflightOrder);
        if (i > 0){
            if (iflightOrderVo.getPnrVo().getTravelerVoList() != null &&
                    iflightOrderVo.getPnrVo().getTravelerVoList().size() > 0){
                for (TravelerVo travelerVo : iflightOrderVo.getPnrVo().getTravelerVoList()) {
                    IflightPassenger iflightPassenger = new IflightPassenger();
                    iflightPassenger.setOrderid(id);

                    //成人
                    if (travelerVo.getType().equals("成人")){
                        if (iflightOrderVo.getAldultPrice() != null && !iflightOrderVo.getAldultPrice().equals("")){
                            iflightPassenger.setSettleamount(new BigDecimal(iflightOrderVo.getAldultPrice()));
                            iflightPassenger.setPassengertype(1l);
                        }
                    }
                    //儿童
                    else if (travelerVo.getType().equals("儿童")){
                        if (iflightOrderVo.getChildPrice() != null && !iflightOrderVo.getChildPrice().equals("")){
                            iflightPassenger.setSettleamount(new BigDecimal(iflightOrderVo.getChildPrice()));
                            iflightPassenger.setPassengertype(2l);
                        }
                    }
                    //婴儿
                    else if (travelerVo.getType().equals("婴儿")){
                        if (iflightOrderVo.getBabyPrice() != null && !iflightOrderVo.getBabyPrice().equals("")){
                            iflightPassenger.setSettleamount(new BigDecimal(iflightOrderVo.getBabyPrice()));
                            iflightPassenger.setPassengertype(3l);
                        }
                    }

                    try {
                        iflightOrder.setCreateTime(new Date());
                    } catch (Exception e){
                        throw new Exception("日期转换错误");
                    }

                    iflightPassenger.setFirstname(travelerVo.getName().substring(1));
                    iflightPassenger.setLastname(travelerVo.getName().substring(0, 1));
                    iflightPassenger.setCountryid(travelerVo.getCitizenship());
                    if (travelerVo.getSex().equals("男")){
                        iflightPassenger.setSex("male");
                    }
                    else if (travelerVo.getSex().equals("女")){
                        iflightPassenger.setSex("female");
                    }

                    iflightPassenger.setMobile(travelerVo.getPhone());
                    iflightPassenger.setIdtype(travelerVo.getIdtype());
                    iflightPassenger.setIdno(travelerVo.getIdno());
                    if (travelerVo.getDocumentsDate() != null){
                        iflightPassenger.setIdvaliddate(dateFormat.parse(travelerVo.getDocumentsDate()));
                    }

                    if (travelerVo.getBirthday() != null){
                        iflightPassenger.setBirthday(dateFormat.parse(travelerVo.getBirthday()));
                    }

                    if (token != null && !token.equals("")){
                        Employee employee = remoteCustomerService.getLoginEmployeeByToken(token).getData();
                        iflightPassenger.setCreateemployeeid(employee.getEmployeeId());
                    }
                    else {
                        iflightPassenger.setCreateemployeeid(10l);
                    }

                    iflightPassenger.setAirliner(iflightOrderVo.getPnrVo().getOutbound().get(0).getAirline());
                    iflightPassenger.setFlightNo(iflightOrderVo.getPnrVo().getOutbound().get(0).getFlightNumber());
                    if (iflightOrderVo.getPnrVo().getOutbound().get(0).getDepartureTime() != null){
                        iflightPassenger.setDepartureTime(format.parse(iflightOrderVo.getPnrVo().getOutbound().get(0).getDepartureTime()));
                    }

                    if (iflightOrderVo.getPnrVo().getOutbound().get(0).getArrivalTime() != null){
                        iflightPassenger.setArrivalTime(format.parse(iflightOrderVo.getPnrVo().getOutbound().get(0).getArrivalTime()));
                    }

                    iflightPassenger.setCabin(iflightOrderVo.getPnrVo().getOutbound().get(0).getPosition());
                    iflightPassenger.setFlightType(FlightOrderConstants.outbound.getValue());
                    iflightPassenger.setDepartureCity(iflightOrderVo.getPnrVo().getOutbound().get(0).getSetOff());
                    iflightPassenger.setArrivalCity(iflightOrderVo.getPnrVo().getOutbound().get(0).getArrive());

                    if (iflightPassenger.getCountryid() == null || iflightPassenger.getCountryid().equals("")){
                        iflightPassenger.setCountryid("中国");
                    }
                    int passenger = iflightPassengerMapper.insertIflightPassenger(iflightPassenger);
                    if (passenger <= 0){
                        throw new Exception(travelerVo.getName() + "，数据创建失败(去程)");
                    }

                    if (iflightOrder.getOutboundReturnJourney().equals(FlightOrderConstants.rt.getValue())){
                        iflightPassenger.setAirliner(iflightOrderVo.getPnrVo().getJourney().get(0).getAirline());
                        iflightPassenger.setFlightNo(iflightOrderVo.getPnrVo().getJourney().get(0).getFlightNumber());
                        if (iflightOrderVo.getPnrVo().getJourney().get(0).getDepartureTime() != null){
                            iflightPassenger.setDepartureTime(format.parse(iflightOrderVo.getPnrVo().getJourney().get(0).getDepartureTime()));
                        }

                        if (iflightOrderVo.getPnrVo().getJourney().get(0).getArrivalTime() != null){
                            iflightPassenger.setArrivalTime(format.parse(iflightOrderVo.getPnrVo().getJourney().get(0).getArrivalTime()));
                        }

                        iflightPassenger.setCabin(iflightOrderVo.getPnrVo().getJourney().get(0).getPosition());
                        iflightPassenger.setFlightType(FlightOrderConstants.journey.getValue());
                        iflightPassenger.setDepartureCity(iflightOrderVo.getPnrVo().getJourney().get(0).getSetOff());
                        iflightPassenger.setArrivalCity(iflightOrderVo.getPnrVo().getJourney().get(0).getArrive());
                        passenger = iflightPassengerMapper.insertIflightPassenger(iflightPassenger);
                        if (passenger <= 0){
                            throw new Exception(travelerVo.getName() + "，数据创建失败（返程）");
                        }
                    }
                }
            }
            IflightPayment iflightPayment = new IflightPayment();
            iflightPayment.setOrderid(id);
            iflightPayment.setJsjid(tmpCustomerIdVoApi.getCustomerId());

            try {
                iflightPayment.setCreateTime(new Date());
            } catch (Exception e){
                throw new Exception("日期转换错误");
            }

            iflightPayment.setJsjname(tmpCustomerIdVoApi.getCustomerName());
            iflightPayment.setJsjcardnum(tmpCustomerIdVoApi.getCustomerCard());
            int payment = iflightPaymentMapper.insertIflightPayment(iflightPayment);
            if (payment <= 0){
                throw new Exception("创建支付信息失败");
            }

            if (iflightOrderVo.getWhetherBill().equals("true")){
                IflightOrderInvoice iflightOrderInvoice = new IflightOrderInvoice();
                iflightOrderInvoice.setOrderid(id);
                iflightOrderInvoice.setInvoicetitle(iflightOrderVo.getInvoice());
                iflightOrderInvoice.setVatno(iflightOrderVo.getCoordinatesgd());
                if (iflightOrderVo.getInvoiceAmount() != null && !iflightOrderVo.getInvoiceAmount().equals("")){
                    iflightOrderInvoice.setInvoiceamont(Long.valueOf(iflightOrderVo.getInvoiceAmount()));
                }

                iflightOrderInvoice.setEmail(iflightOrderVo.getEmail());
                iflightOrderInvoice.setPhone(iflightOrderVo.getTelephone());
                iflightOrderInvoice.setUsername(iflightOrderVo.getContact());
                iflightOrderInvoice.setBankName(iflightOrderVo.getBankName());
                iflightOrderInvoice.setAddress(iflightOrderVo.getAddress());
                iflightOrderInvoice.setBankAccount(iflightOrderVo.getAccount());
                int invoice = iflightOrderInvoiceMapper.insertIflightOrderInvoice(iflightOrderInvoice);
                if (invoice <= 0){
                    throw new Exception("发票信息创建失败");
                }
            }

//            redisService.setCacheObject(FLIGHT + tmpCustomerIdVoApi.getCustomerId() + ORDER + orderNum, JSON.toJSON(iflightOrder), 60 * 3000L, TimeUnit.SECONDS);

            Date date = new Date();
            String newDate = format.format(date);
            String messageContent = "您在" + newDate + "，将订单号为" + iflightOrderVo.getOrderNum() + "的订单改签至" + iflightOrderVo.getPnrVo().getOutbound().get(0).getDepartureTime();
            Map<String,String> map = new HashMap<>();
            map.put("customerId", tmpCustomerIdVoApi.getCustomerId().toString());
            map.put("messageContent", messageContent);
            map.put("businessType", BusinessTypeConstants.flight.getValue());
            map.put("businessOrderId", orderNum.toString());
            remoteCustomerService.addCustomerMessage(map);

            return 1;
        }
        else {
            throw new Exception("国际机票订单创建失败");
        }
    }

    /**
     * 国际机票支付结果
     * 国际机票支付参数, 支付结果, 预留款
     * */
    public int payResult(InternationalPayVo internationalPayVo, String result, String reserveMoney, String externalBillNo){
        int count = 0;
        IflightOrder iflightOrder = iflightOrderMapper.selectIflightOrderById(internationalPayVo.getOrderId());
        if (reserveMoney != null && !reserveMoney.equals("")){
            iflightOrder.setDeposit(new BigDecimal(reserveMoney));
        }

        CustomerIdVoApi customerIdVoApi = new CustomerIdVoApi();
        customerIdVoApi.setCustomerId(internationalPayVo.getCustomerId());
        customerIdVoApi = remoteCustomerService.customerIdApi(customerIdVoApi);
        iflightOrder.setMembercardid(customerIdVoApi.getCustomerCard());
        iflightOrder.setPaystatus(result);
        if (result.equals("true")){
            iflightOrder.setStatus(FlightOrderConstants.payd.getValue());
        }
        else {
            iflightOrder.setStatus(FlightOrderConstants.failPay.getValue());
        }
        int i = iflightOrderMapper.updateIflightOrder(iflightOrder);

        if (i > 0){
            IflightPayment iflightPayment = new IflightPayment();
            iflightPayment.setOrderid(internationalPayVo.getOrderId());
            iflightPayment.setJsjid(internationalPayVo.getCustomerId());
            iflightPayment.setPartnername(internationalPayVo.getPayType());
            iflightPayment.setAmount(new BigDecimal(internationalPayVo.getMoneyAmout()));
            iflightPayment.setTradeorderid(iflightOrder.getOrderid().toString());
            iflightPayment.setTradetime(new Date());
            if (result.equals("true")){
                iflightPayment.setStatus(1l);
            }
            else {
                iflightPayment.setStatus(0l);
            }

            if (reserveMoney.equals("0")){
                if (result.equals("true")){
                    if (externalBillNo != null){
                        iflightPayment.setExternalbillno(externalBillNo);
                    }
                    iflightPayment.setStatusmsg("易宝支付成功");
                }
                else {
                    iflightPayment.setStatusmsg("易宝支付失败");
                }
            }
            else {
                if (result.equals("true")){
                    iflightPayment.setStatusmsg("预留款支付成功");
                }
                else {
                    iflightPayment.setStatusmsg("预留款支付失败");
                }
            }
            int payment = iflightPaymentMapper.updateIflightPayment(iflightPayment);
            if (payment > 0){
                count = 1;
            }
        }

        return count;
    }

    /**
     * 国际机票退款操作
     * */
    public int cancel(CancelVo cancelVo, int count) throws Exception {
        Date date = new Date();
        IflightOrder iflightOrder = iflightOrderMapper.selectIflightOrderById(cancelVo.getId());
        if (count == 0){
            iflightOrder.setChangestatus(FlightOrderConstants.refundProgress.getValue());
            iflightOrder.setStatus(FlightOrderConstants.refundProgress.getValue());
        }
        else if (count == 1){
            iflightOrder.setChangestatus(FlightOrderConstants.RefundTicketSuccess.getValue());
            iflightOrder.setStatus(FlightOrderConstants.RefundTicketSuccess.getValue());
        }
        int i = iflightOrderMapper.updateIflightOrder(iflightOrder);
        if (i <= 0){
            throw new Exception("订单状态修改失败");
        }

        for (Long aLong : cancelVo.getPassengerIdList()) {
            IflightPassenger iflightPassenger = iflightPassengerMapper.selectIflightPassengerById(aLong);
            iflightPassenger.setRfeeamount(new BigDecimal(cancelVo.getHandlingFee()));
            iflightPassenger.setRamount(new BigDecimal(cancelVo.getAmount()));
            iflightPassenger.setRefundtype(1l);
            int passenger = iflightPassengerMapper.updateIflightPassenger(iflightPassenger);
            if (passenger <= 0){
                throw new Exception(iflightPassenger.getLastname() + iflightPassenger.getFirstname() + "订单状态修改失败");
            }
        }

        IflightRefund iflightRefund = new IflightRefund();
        iflightRefund.setOrderid(cancelVo.getId());
        iflightRefund.setRefundtype(3l);
        if (cancelVo.getType().equals(FlightOrderConstants.backtrack.getValue())){
            iflightRefund.setRefundtypeway(1l);
        }
        else if (cancelVo.getType().equals(FlightOrderConstants.reserveMoney.getValue())){
            iflightRefund.setRefundtypeway(2l);
        }
        iflightRefund.setRefundstatus(32l);

        BigDecimal amount = new BigDecimal(cancelVo.getAmount()).add(new BigDecimal(cancelVo.getHandlingFee()));
        iflightRefund.setRtotalamount(amount);
        iflightRefund.setRamount(new BigDecimal(cancelVo.getAmount()));
        iflightRefund.setRfeeamount(new BigDecimal(cancelVo.getHandlingFee()));
        iflightRefund.setOperatetime(date);
        iflightRefund.setOperateemployeeid(cancelVo.getEmployeeId());
        iflightRefund.setCreateTime(date);
        iflightRefund.setCreateemployeeid(cancelVo.getEmployeeId());
        iflightRefund.setRemark(cancelVo.getRemark());
        int refund = iflightRefundMapper.insertIflightRefund(iflightRefund);
        if (refund <= 0){
            throw new Exception("订单退票信息添加失败");
        }

        IflightRefundbankcard iflightRefundbankcard = new IflightRefundbankcard();
        iflightRefundbankcard.setRefundid(iflightRefund.getRefundid());
        iflightRefundbankcard.setEmployeeid(cancelVo.getEmployeeId());
        iflightRefundbankcard.setCreateTime(date);
        int refundbankcard = iflightRefundbankcardMapper.insertIflightRefundbankcard(iflightRefundbankcard);
        if (refundbankcard <= 0){
            throw new Exception("订单退款信息添加失败");
        }

        for (Long aLong : cancelVo.getPassengerIdList()) {
            IflightPassenger iflightPassenger = iflightPassengerMapper.selectIflightPassengerById(aLong);
            if (iflightPassenger.getFlightType().equals(FlightOrderConstants.outbound.getValue())){
                IflightRefundandpassenger iflightRefundandpassenger = new IflightRefundandpassenger();
                iflightRefundandpassenger.setRefundid(iflightRefund.getRefundid());
                iflightRefundandpassenger.setPassengerid(iflightPassenger.getPassengerid());
                iflightRefundandpassenger.setPassengername(iflightPassenger.getLastname() + iflightPassenger.getFirstname());
                iflightRefundandpassenger.setRfeeamount(Long.valueOf(cancelVo.getHandlingFee()));
                iflightRefundandpassenger.setRamount(Long.valueOf(cancelVo.getAmount()));
                iflightRefundandpassenger.setRefundtype(1l);
                int refundandpassenger = iflightRefundandpassengerMapper.insertIflightRefundandpassenger(iflightRefundandpassenger);
                if (refundandpassenger <= 0){
                    throw new Exception(iflightPassenger.getLastname() + iflightPassenger.getFirstname() + "订单退票详情添加失败");
                }
            }
        }
        return 1;
    }
}
